﻿import requests
import os
# 定义照片URL地址l
url = "http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"

response = requests.get(url)
# 判断响应状态码是否为200，即判断请求是否成功
if response.status_code == 200:
    # 获取桌面路径
    desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
    # 定义保存文件的路径
    save_path = os.path.join(desktop_path, "photo.jpg")
    # 将照片内容写入文件
    with open(save_path, "wb") as f:
        f.write(response.content)
    # 输出保存成功提示
    print("已将照片保存至桌面)
else:
    # 输出请求失败提示
    print("请求照片失败，状态码为)